﻿(function() {
    nova.View = function (url, wrapper) {
        this.url = url;
        this.wrapper = wrapper == undefined ? "#body" : wrapper;
    };

    nova.View.prototype.onLoaded = null;

    nova.View.prototype.load = function () {
        var obj = this;
        $.ajax({
            url: obj.url + "?timestamp=" + new Date().getTime(),
            dataType: "html",
            type: "get",
            success: function (html) {
                try {
                    setTimeout(function () { });//this is used to fix android 4.1 querks
                    $(obj.wrapper).html(html);
                    $(obj).trigger("onViewLoaded");
                    obj.onLoaded && obj.onLoaded();
                } catch (ex) {
                    alert('loading view: "' + obj.url + '" error: ' + ex);
                }
            },
            error: function (err) {
                var errorEvt = $.Event("onLoadingError");
                errorEvt.data = err;
                $(obj).trigger(errorEvt);
            }
        });
    };

    nova.View.prototype.GetHtml = function () {
        return $(this.wrapper).html();
    };

    nova.View.prototype.onViewLoaded = function (callback) {
        $(this).bind("onViewLoaded", callback);

    };

    nova.View.prototype.onLoadingError = function (callback) {
        $(this).bind("onLoadingError", callback);
    };
})();


